<?php

namespace app\index\controller;

use think\Controller;
use think\Db;

/**
 * 任务计划控制器
 **/
class Dd extends Controller
{
	public function actionReceiveCallBack(){

//接收值 sign 时间戳

		$signature=$_GET['signature'];

		$nonce=$_GET['nonce'];

		$timeStamp=$_GET['timestamp'];

		$suiteKey=Yii::$app->params['corpid'];//必填，企业ID

		$token="dingtalk";    //必须和在注册是一样

//接收传过来的需要解密的值

		$postdata = file_get_contents("php://input");

		$postList = json_decode($postdata,true);

		$encrypt = $postList['encrypt'];

//注册时加密的key

		$aesKey=\Yii::$app->params['aes_key'];

		$aes_key_encode=base64_encode($aesKey);

		$aes_key=substr($aes_key_encode,0,-1);

		$decryptMsg="";

		$crypt = new DingCallbackCrypt($token,$aes_key,$suiteKey);

		$encryData = $crypt->DecryptMsg($signature,$timeStamp,$nonce,$encrypt,$decryptMsg);  //解密

		if($encryData['errcode']!==0){

		}else{

			if($newData->EventType=="bpms_task_change"||$newData->EventType=="bpms_instance_change"){

				$dingtalk=new DingtalkController();

				$dingtalk->UpdateProcess($newData->processInstanceId);

			}

			$msg="success";

			$encryptMsg="";

			$data = $crypt->EncryptMsg($msg,$timeStamp,$nonce,$encryptMsg);   //加密

			if($data['errcode']!=0){

			}else{

				return $data['data'];   //返回加密成功的json数据

			}

		}

	}
}